<div class="autosearch_video">
	<ul>
		<?php
			   $feedURL = 'http://gdata.youtube.com/feeds/api/standardfeeds/most_viewed';
		//try{
		//	throw new Exception('Error connect api youtube.');	
		// read feed into SimpleXML object
			$sxml = simplexml_load_file($feedURL);
		
		// iterate over entries in feed
		foreach ($sxml->entry as $entry) {
		  // get nodes in media: namespace for media information
		  $media = $entry->children('http://search.yahoo.com/mrss/');
		  
		  // get video player URL
		  $attrs = $media->group->player->attributes();
		  $watch = $attrs['url']; 
		  //var_dump($watch);
		  
		  // get video thumbnail
		  $attrs = $media->group->thumbnail[0]->attributes();
		  $thumbnail = $attrs['url']; 
				
		  // get <yt:duration> node for video length
		  $yt = $media->children('http://gdata.youtube.com/schemas/2007');
		  $attrs = $yt->duration->attributes();
		  $length = $attrs['seconds']; 
		  
		  // get <yt:stats> node for viewer statistics
		  $yt = $entry->children('http://gdata.youtube.com/schemas/2007');
		  $attrs = $yt->statistics->attributes();
		  $viewCount = $attrs['viewCount']; 
		  
		  // get <gd:rating> node for video ratings
		  $gd = $entry->children('http://schemas.google.com/g/2005'); 
		  if ($gd->rating) {
			$attrs = $gd->rating->attributes();
			$rating = $attrs['average']; 
		  } else {
			$rating = 0; 
		  } 
		  ?>
				<li>
					<a href="<?php //http://www.youtube.com/watch?v=e82VE8UtW8A&feature=youtube_gdata_player
					$str = '&feature=youtube_gdata_player';
					$replate = '&amp;hl=en&amp;fs=1&amp;autoplay=1;loop =1;repeat=1';
					$watch_video = str_replace($str,$replate,$watch,$count);
					$str = 'http://www.youtube.com/watch?v=';
					$replate = 'http://www.youtube.com/v/';
					$watch_video = str_replace($str,$replate,$watch_video,$count);
					echo $watch_video; 
					
					?>"><img src="<?php echo $thumbnail;?>" /></a>
				<div class="block">
						<h2><a href="<?php echo $watch_video; ?>"><?php echo $media->group->title; ?></a></h2>
					<span class="attr">- By</span> <span class="view">:&nbsp; <?php echo $entry->author->name; ?> </span>
					<span class="attr">- Duration</span> <span class="view">:&nbsp;<?php printf('%0.2f', $length/60); ?> </span>
					<span class="attr"> - Views</span> <span class="view">:&nbsp;<?php echo $viewCount; ?></span>
					<p><?php echo $media->group->description; ?> </p>
				</div>
			</li>
		<?php }
			//}
			//catch (Exception $e){
			//	echo "<li>Caught exception".$e->getMessage()."</li>";
			//}
			
			;?>
	</ul>
	<script>
	$(document).ready(function() {	
		//Click and Hover events for thumbnail list
		$(".autosearch_video ul li:first").addClass('active'); 
		$(".autosearch_video ul li").click(function(){ 
			//Set Variables
			var imgAlt = $(this).find('img').attr("alt"); //Get Alt Tag of Image
			var imgTitle = $(this).find('a').attr("href"); //Get Main Image URL
			var imgDesc = $(this).find('.block').html(); 	//Get HTML of block
			var imgDescHeight = $(".main_image").find('.block').height();	//Calculate height of block	
			
			if ($(this).is(".active")) {  //If it's already active, then...
				return false; // Don't click through
			} else {
				//Animate the Teaser				
				$(".main_image .block").animate({ opacity: 0, marginBottom: -imgDescHeight }, 250 , function() {
					$(".main_image .block").html(imgDesc).animate({ opacity: 0.85,	marginBottom: "0" }, 250 );
					$(".main_image object").attr({ data: imgTitle , alt: imgAlt});
				});
			}
			
			$(".autosearch_video ul li").removeClass('active'); //Remove class of 'active' on all lists
			$(this).addClass('active');  //add class of 'active' on this list only
			
			return false;
			
		})
	});//Close Function
</script>
</div>				